<template>
  <div>
    <nav>
      <van-nav-bar>
        <template #left>
          <van-icon name="arrow-left" color="#0c0c0c"  @click="back" size="16" />
          <div class="author">
            <img :src="noteData.user.avatar" alt="" />
            <span>{{noteData.user.username}}</span>
            <img
              src="https://oss-xpc0.xpccdn.com/Upload/edu/2019/09/055d70f8a79a45b.png"
              alt=""
              class="vip"
              v-show="noteData.user.vip_flag === 1"
            />
          </div>
        </template>
        <template #right>
          <button>+ 关注</button>
          <van-icon name="share-o" color="#0c0c0c" size="16" />
        </template>
      </van-nav-bar>
    </nav>
    <div class="content">
      <div class="img-box">
        <viewer :images="imgArr">
        <img :src=item  alt="" v-for="(item,i) in imgArr" :key="i"  />
        </viewer>
      </div>
      <div class="bottom">
        <h3>{{noteData.title}}</h3>
        <p>{{text}}</p>
        <div class="bottom-left">
          <div class="time">{{new Date(noteData.addtime * 1000)
                    .toLocaleString()
                    .replace(/\//g, "-").slice(5)}} .</div>
          <div class="location">{{noteData.ip_location}}</div>
        </div>
      </div>
    </div>
    <div class="commend">
      <div class="top">
        <div class="top-left">
          <img src="@/assets/user.png" alt="" />
        </div>

        <input type="text" placeholder="说说你的看法吧" />
      </div>
      <div class="bottom" v-for="(item,i) in commentData" :key="i">
        <div class="bottom-left">
          <img :src="item.userDetail.avatar_big" alt="" />
        </div>
        <div class="bottom-right">
          <div class="bottom-right-top">
            <div>
              <span>{{item.userDetail.user_name}}</span>
             
              <img
              src="https://oss-xpc0.xpccdn.com/Upload/edu/2019/09/055d70f8a79a45b.png"
              alt=""
              class="vip"
              v-show="item.userDetail.vip_flag === 1"
            />
            
            </div>
            <div class="icon">
              {{item.dislikeCount==0?"":dislikeCount}}<van-icon name="good-job-o" size="16" color="#000" />
            </div>
          </div>
          <div class="bottom-right-bottom">
            <p>{{item.contentText}}</p>
            <span>{{new Date(item.createTime)
                    .toLocaleString()
                    .replace(/\//g, "-").slice(5,10)}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import VueAxios from "vue-axios";
export default {
    data() {
        return {
        active: 0,
        noteData:{
            user: {
                location:{
                    city: {},
                }
                
            },
        },
        imgArr:[],
        text:"",
        commentData:[],
        };
    },
    methods: {
       getNoteData(id){
        axios({
            method: "get",
            url: `https://apis.netstart.cn/xpc/note/${id}`,
            
        }).then((res) => {
            this.noteData = res.data.data;
            this.imgArr = res.data.data.images;
            this.text=res.data.data.content;
            this.text.replace(/\n/g, '<br/>');
        });
        
       },
       getComment(id){
            axios({
                method: "get",
                url: `https://apis.netstart.cn/xpc/note/${id}/comment`,
                
            }).then((res) => {
                this.commentData = res.data.data;
            });
       },
       back(){
              this.$router.go(-1);
       },
    },
    mounted() {
      this.getNoteData(this.$route.query.id);
      this.getComment(this.$route.query.id);
    },
    
};
</script>
<style lang="scss">
nav {
  .van-nav-bar {
    height: 12.0773vw;
    padding: 0 15px;
    .van-nav-bar__content {
      width: 100%;
      height: 12.0773vw;
    }
    img {
      width: 5.7971vw;
      height: 5.7971vw;
      border-radius: 50%;
      margin-left: 20px;
      
    }
    .author {
      display: flex;
      align-items: center;
      span {
        margin-left: 20px;
      }
    }
    button {
      width: 15.7005vw;
      margin-right: 20px;
      height: 6.5217vw;
      border-radius: 25px;
      color: #b86455;
      border: 1px solid #b86455;
      background: #fff;
    }
  }
}
.content {
  margin-top: 20px;
  padding: 0 3.4232vw;
  border-bottom: 1px solid #ccc;
  padding-bottom: 20px;
  .img-box {
    margin-bottom: 5px;
    img {
      width: 29.2271vw;
      height: 29.2271vw;
      margin-right: 10px;
      border-radius:10px;
      margin-bottom: 10px;
    }
  }
  h3{
    margin-bottom: 10px;
  }
  p{
    white-space: pre-wrap;
    letter-spacing:.5px;
    font-size: 16px;
  }
  .bottom-left {
    margin-top: 20px;
    display: flex;
    line-height:10px;
    color:#999;
    font-style: 12px;
    div {
      margin-right: 20px;
    }
  }
}
.commend {
  margin-top: 20px;
  padding: 0 3.4232vw;
  padding-bottom: 60px;
  .top {
    display: flex;
    align-items: center;
    margin-bottom: 30px;

    img {
      width: 40px;
      height: 34px;
      border-radius: 50%;
      margin-right: 10px;
      
    }
    input {
      height: 37px;
      border: 1px solid #ccc;
      border-radius: 25px;
      padding: 5px 20px;
      flex-grow: 1;
    }
  }
  .bottom {
    display: flex;
    margin: 25px 0;
   
    
    img {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      margin-right: 10px;
    //   padding:0px 15px 20px 0;   
    }
    .bottom-right {
      margin-left: 10px;
      flex-grow: 1;
      padding-bottom: 30px;
      border-bottom: 1px solid #ccc;
      .bottom-right-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        img{
            width: 3.8647vw;
            height: 3.8647vw;
        }
        span {
          margin-right: 10px;
        }
        .icon {
          margin-right: 5px;
        }
      }
      .bottom-right-bottom {
        margin-top: 10px;
        display: flex;
        align-items: center;
        line-height: 1.5;
        span {
          margin-left: 10px;
        }
      }
    }
  }
}
</style>